#请勿使用!!!!!!!需要修改!!!!!!!

#关闭防火墙
firewall-cmd --state
systemctl stop firewalld.service
systemctl disable firewalld.service
#关闭交换内存，kubelet不支持开启swap分区时使用
swapoff -a && sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab
#设置 /etc/selinux/config中 SELINUX=disabled
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config

echo '#关闭交换空间,系统OOM 才允许使用
vm.swappiness = 0
#开启OOM
vm.panic_on_oom=0
#有了它,ipvs才能进行转发
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
net.ipv4.vs.conntrack=1
#关闭ipv6
net.ipv6.conf.all.disable_ipv6=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
#开启文件句柄数目
fs.file-max=52706936
fs.nr_open=52706936
net.netfilter.nf_conntrack_max=2310720' > /etc/sysctl.d/kubernetes.conf
sysctl --system

mkdir /var/log/journal
mkdir /etc/systemd/journald.conf.d
echo '[Journal]
#持久化保存到磁盘
Storage=persistent
#压缩历史日志
Compress=yes
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=1000
#最大占用空间
SystemMaxUse=10G
#单日志最大文件200M
SystemMaxFileSize=200M
#日志保存时间两周
MaxRetentionSec=2week
#不将日志转发到syslog
ForwardToSyslog=no
#######################' > /etc/systemd/journald.conf.d/99-prophet.conf
systemctl restart systemd-journald

#卸载原有版本
yum -y remove docker docker-common docker-selinux docker-engine
#安装所需的依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
#设置stable镜像仓库
yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
#更新软件包索引
yum makecache fast
#安装Docker CE（这是安装最新版本）
yum install docker-ce
#配置docker
mkdir -p /etc/docker/
echo '{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
    "max-size": "100m"
    },
    "storage-driver": "overlay2",
       "storage-opts": [
       "overlay2.override_kernel_check=true"
    ]
}' > /etc/docker/daemon.json
#启动服务
systemctl enable docker
systemctl start docker

#设置源
echo '[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg' > /etc/yum.repos.d/kubernetes.repo

#安装kuebadm
yum -y install kubeadm kubectl kubelet
systemctl enable kubelet
systemctl start kubelet
#安装helm
wget https://get.helm.sh/helm-v3.5.3-linux-amd64.tar.gz
tar -xf helm-v3.5.3-linux-amd64.tar.gz
cp -a linux-amd64/helm /usr/local/bin/
chmod a+x /usr/local/bin/helm 
#添加stable仓库
helm repo add stable https://charts.helm.sh/stable

#主节点执行
#kubeadm init --config=kubeadm-config.yaml --upload-certs | tee kubeadm-init.log
